public class Test {
    public static String toLowerCase(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        //遍历字符数组
        for(int i = 0; i < s.length(); i++){
            //获取i下标内容
            char ch = s.charAt(i);
            //判断是不是字母
            if(Character.isLetter(ch)) {
                //判断是不是大写字母
                if(Character.isUpperCase(ch)){
                    //是大写字母则转换成小写字母
                    ch = (char)(ch + 32);
                }
            }
            //拼接
            stringBuilder.append(ch);
        }
        return stringBuilder.toString();
    }

    public static int countSegments(String s) {
        int count = 0;
        String[] result = s.split(" ");
        for(int i = 0; i < result.length; i++){
            if(result[i].length() != 0) {
                count++;
            }
        }
        return count;
    }
    public static void main(String[] args) {
        String s ="Hello World";
        //String result = toLowerCase(s);
        int result = countSegments(s);
        System.out.println(result);
    }
}
